
from flask_cors import CORS,cross_origin
from flask import Flask,Blueprint,redirect,url_for,render_template

#生成实例
app=Flask(__name__)



@app.route('/')
def welcome():
    return '欢迎进入该程序！'

@app.route('/final/<username>')
def welcome1(username):
    return f'欢迎进入跳转程序！{username}'

#重定向
@app.route('/index/<name>')
def indexpage(name):
    #函数名
    return redirect(url_for("welcome1",username=name))

@app.route('/indexbd/')
def indexbd():
    #函数名
    return redirect('https://www.baidu.com')


@app.route('/displayvar/')
def disvar():
    data=[
        {"name":"zhangsan","age":21,"gender":"male"},
        {"name": "wangwu", "age": 22, "gender": "female"}
          ]
    return render_template('displayvar.html',var=data)




@app.route('/')
def goods_commend():
    return "好物推荐"

#声明蓝图
blueobj=Blueprint('goods',import_name=__name__,url_prefix='/blueprint')

@blueobj.route('/recommend/')
def gp():
    return 'hehe推荐'

@blueobj.route('/add_goods',methods=['post'])
def add_g():
    print('内容：',url_for('goods.add_g'))
    return {"count":123,"detail":[],"msg":'添加成功'}






CORS(app,supports_credentials=True)




#
@app.route('/hellokitty/')
def hello_k():
    return 'hello kitty'




if __name__ == '__main__':
    app.register_blueprint(blueobj)
    app.run(debug=True)






























